package com.ndp.fb.mongo.model;

import com.mongodb.ReflectionDBObject;
import com.restfb.util.StringUtils;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;

/**
 * 单个ad留存
 * Created by jacky.cheng on 2015/10/8.
 */
@Setter
@Getter
@NoArgsConstructor
public class AdGroupRetention extends ReflectionDBObject implements Serializable {
    private Long adGroupId;
    private Date day;
    private Integer install;
    private Map<String,Integer> opens;

    public void parseLineData(String line) throws ParseException {
        String[] split=new String[10];
        String[] inputs = line.split(",");
        for (int i = 0; i < 10; i++) {
            if (inputs.length>i){
                if (StringUtils.isBlank(inputs[i])) {
                    split[i] = "0";
                }else {
                    split[i]=inputs[i];
                }
            }else {
                split[i]="0";
            }
        }
        setAdGroupId(Long.valueOf(split[0]));
        SimpleDateFormat e = new SimpleDateFormat("yyyy-MM-dd");
        e.setTimeZone(TimeZone.getTimeZone("UTC"));
        setDay(e.parse(split[1]));
        setInstall(Integer.valueOf(split[2]));
        opens=new HashMap<>();
        opens.put("open1",Integer.valueOf(split[3]));
        opens.put("open2",Integer.valueOf(split[4]));
        opens.put("open3",Integer.valueOf(split[5]));
        opens.put("open4",Integer.valueOf(split[6]));
        opens.put("open5",Integer.valueOf(split[7]));
        opens.put("open6",Integer.valueOf(split[8]));
        opens.put("open7",Integer.valueOf(split[9]));
    }

}
